#2859 Support changing format inside entity #2896
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change is to support changing format inside an entity.
Not like normal content, entity is owned by its creator (normally a plugin), so our format code will skip all entity and keep it not changed. However, some requirements come and they want some of the entity content can also be formatted. So in this change I added a new entity operation
beforeFormat
, it will be triggered whenformatSegmentWithContentModel
is called, this is used by most of the segment format APIs such as toggleBold and setTextColor.Plugin can handle entityOperation event and check the entity type and id, then put the root element of content that you want to format into
formattableRoots
property of this event object. After that roosterjs will create content model for each root and do format changes.There is a sample change in
SampleEntityPlugin.ts
in this PR that shows how to use this event.